package com.example.util;

import android.content.Context;
import android.content.pm.PackageManager;
import android.hardware.Camera;
import android.util.Log;

public class CameraUtil {
    /** Check if this device has a camera */
    public boolean checkCameraHardware(Context context) {
        if (context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA)){
            // this device has a camera
            return true;
        } else {
            // no camera on this device
            return false;
        }
    }

    /**
     * 检查是否可以使用摄像头功能
     * @return 可以使用摄像头 返回对象，否则返回null
     */
    public static Camera canCamera() {
        Camera c = null;
        try {
            c = Camera.open(); // attempt to get a Camera instance
        }
        catch (Exception e){
            Log.d("adasd", "", e);
            // Camera is not available (in use or does not exist)
        }
        return c; // returns null if camera is unavailable
    }



}
